package com.junzhiit.nengji.cms.web.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.cms.service.ModulesGoodsService;
import com.junzhiit.nengji.cms.web.vo.DataTablesParamVO;
import com.junzhiit.nengji.cms.web.vo.GoodsListVO;
import com.junzhiit.nengji.cms.web.vo.ModulesGoodsAddVO;
import com.junzhiit.nengji.cms.web.vo.ModulesGoodsListVO;
import com.junzhiit.nengji.cms.web.vo.ModulesGoodsSortVO;
import com.junzhiit.nengji.cms.web.vo.ResultVO;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/modules/goods")
public class ModulesGoodsController extends BaseController {

	@Autowired
	private ModulesGoodsService modulesGoodsService;

	@ApiOperation(value = "获取该模块商品")
	@RequestMapping(method = RequestMethod.GET)
	public Map<String, Object> findAll(DataTablesParamVO dtp, ModulesGoodsListVO modulesGoodsListVO) {
		AssertUtil.notBlank(modulesGoodsListVO.getModulesId(), "modulesId is required.");
		return modulesGoodsService.findAll(dtp, modulesGoodsListVO);
	}

	@ApiOperation(value = "获取该模块商品总数")
	@RequestMapping(value = "/count/{id}", method = RequestMethod.GET)
	public ResultVO getTotalCount(@PathVariable String id) {
		return modulesGoodsService.getTotalCount(id);
	}

	@ApiOperation(value = "添加模块商品")
	@RequestMapping(method = RequestMethod.POST)
	public ResultVO add(ModulesGoodsAddVO modulesGoodsAddVO) {
		return modulesGoodsService.add(modulesGoodsAddVO);
	}

	@ApiOperation(value = "查询所有商品(总部商品审核通过的)")
	@RequestMapping(value = "/examine", method = RequestMethod.GET)
	public Map<String, Object> findModulesAll(DataTablesParamVO dtp, GoodsListVO goodsListVO,String sessionId) {
		AssertUtil.notNull(sessionId, "sessionId is required.");
		return modulesGoodsService.findModulesAll(dtp, goodsListVO,sessionId);
	}

	@ApiOperation(value = "移除商品")
	@RequestMapping(method = RequestMethod.DELETE)
	public ResultVO del(String id) {
		AssertUtil.notNull(id, "id is required.");
		return modulesGoodsService.del(id);
	}

	@ApiOperation(value = "商品下移")
	@RequestMapping(value = "sort/down", method = RequestMethod.PUT)
	public ResultVO sortDown(ModulesGoodsSortVO modulesGoodsSortVO) {
		AssertUtil.notBlank(modulesGoodsSortVO.getId(), "id is required.");
		return modulesGoodsService.sortDown(modulesGoodsSortVO);
	}

	@ApiOperation(value = "商品上移")
	@RequestMapping(value = "sort/up", method = RequestMethod.PUT)
	public ResultVO sortUp(ModulesGoodsSortVO modulesGoodsSortVO) {
		AssertUtil.notBlank(modulesGoodsSortVO.getId(), "id is required.");
		return modulesGoodsService.sortUp(modulesGoodsSortVO);
	}

	@ApiOperation(value = "商品置顶")
	@RequestMapping(value = "sort/stick", method = RequestMethod.PUT)
	public ResultVO sortStick(ModulesGoodsSortVO modulesGoodsSortVO) {
		AssertUtil.notBlank(modulesGoodsSortVO.getId(), "id is required.");
		AssertUtil.notBlank(modulesGoodsSortVO.getModulesId(), "modulesId is required.");
		return modulesGoodsService.sortStick(modulesGoodsSortVO);

	}

	@ApiOperation(value = "更新上下架")
	@RequestMapping(value = "status", method = RequestMethod.PUT)
	public ResultVO updateStatus(String id) {
		AssertUtil.notBlank(id, "id is required.");
		return modulesGoodsService.updateStatus(id);
	}

	@ApiOperation(value = "批量更新上下架")
	@RequestMapping(value = "batch/status", method = RequestMethod.PUT)
	public ResultVO batchUpdateStatus(String[] ids, int status) {
		return modulesGoodsService.batchUpdateStatus(ids, status);
	}
	
}
